package com.yu.rabbitmq.two;

import com.rabbitmq.client.Channel;
import com.yu.rabbitmq.utils.RabbitMqUnits;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * 测试消息在手动应答的时候不丢失，会放到队列中重新消费
 */
public class Task02 {

    public static final String TASK_QUEUE_NAME = "ack_queue";

    public static void main(String[] args) {
        try {
            Channel channel = RabbitMqUnits.getChannel();
            //声明队列
            channel.queueDeclare(TASK_QUEUE_NAME,false,false,false,null);
            Scanner scanner = new Scanner(System.in);
            while (scanner.hasNext()){
                String next = scanner.next();
                channel.basicPublish("",TASK_QUEUE_NAME,null,next.getBytes());
                System.out.println("消息发送完成");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }

    }

}
